using System.Linq;
using System.Reflection;
using System.Text;
using NUnit.Framework;

// ReSharper disable InconsistentNaming
namespace NFreeMarker.Tests.Template
{
    public class TemplateTests_ProcessSpecialVariables
    {
        [TestFixture]
        public class When_processing_the_lang_variable : TemplateTestsBase
        {
            [Test]
            public void Assure_the_current_language_is_returned()
            {
                SetTemplateContent("${.lang}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("en"));
            }
        }

        [TestFixture]
        public class When_processing_the_locale_variable : TemplateTestsBase
        {
            [Test]
            public void Assure_the_current_locale_is_returned()
            {
                SetTemplateContent("${.locale}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("en-US"));
            }
        }

        [TestFixture]
        public class When_processing_the_output_encoding_variable : TemplateTestsBase
        {
            [Test]
            public void Assure_the_default_output_encoding_is_returned()
            {
                Configuration.SetOutputEncoding(Encoding.UTF8);
                SetTemplateContent("${.output_encoding}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("utf-8"));
            }
        }

        [TestFixture]
        public class When_processing_the_template_name_variable : TemplateTestsBase
        {
            [Test]
            public void Assure_the_name_of_the_current_template_is_returned()
            {
                SetTemplateContent("${.template_name}");

                string output = ProcessTemplate();

                Assert.That(output, Is.EqualTo("test.ftl"));
            }
        }

        [TestFixture]
        public class When_processing_the_version_variable : TemplateTestsBase
        {
            [Test]
            public void Assure_the_version_is_returned()
            {
                SetTemplateContent("${.version}");

                string output = ProcessTemplate();

                string currentVersion = Assembly
                    .GetAssembly(typeof (NFreeMarker.Template.Template))
                    .GetCustomAttributes(typeof (AssemblyInformationalVersionAttribute), false)
                    .OfType<AssemblyInformationalVersionAttribute>()
                    .First()
                    .InformationalVersion;

                Assert.That(output, Is.EqualTo(currentVersion));
            }
        }
    }
}
// ReSharper enable InconsistentNaming
